from flask import Blueprint
from flask_restful import Api

from .common_resources import (
    GetFileListResource,
    GetFileResource,
    LoginResource,
    UpdatePasswordResource,
)
from .user_resources import (
    AddUserResource,
    SearchResource,
    UpdateUserResource,
    DeleteUserResource,
    GetUserFileListResource,
    SaveAnnotationResource,
    SavePatientResource,
    GetPatientInfoResource, GetPatientInfoListResource, GetImageFeatureResource,
)

from .admin_resources import (
    UploadFileResource,
    CreateFolderResource,
    DownloadFileResource,
    DeleteFileResource,
    TestResource, SendFileResource, GetExcelFileListResource, UpdateFolderNameResource, DownloadMultipleFilesResource,
    batchDownloadJSONResource
)

bp = Blueprint("restapi", __name__, url_prefix="/api/v1")
api = Api(bp)


def init_app(app):
    # 管理员接口
    api.add_resource(CreateFolderResource, '/CreateFolder')
    api.add_resource(UpdateFolderNameResource, '/updateFolderName')
    api.add_resource(UploadFileResource, '/uploadFile')
    api.add_resource(DeleteFileResource, '/DeleteFile')
    api.add_resource(DownloadFileResource, '/downloadFile')
    api.add_resource(DownloadMultipleFilesResource, '/downloadMultipleFiles')
    api.add_resource(batchDownloadJSONResource, '/batchDownloadJSON')
    api.add_resource(SendFileResource, '/SendFile')
    api.add_resource(UpdatePasswordResource, '/updatePassword')

    api.add_resource(TestResource, '/test')

    # 用户接口
    api.add_resource(AddUserResource, '/adduser')
    api.add_resource(DeleteUserResource, '/delete_user')
    api.add_resource(UpdateUserResource, '/update_user')
    api.add_resource(SearchResource, '/search')
    api.add_resource(GetUserFileListResource, '/getUserFileList')
    api.add_resource(SaveAnnotationResource, '/saveAnnotation')
    api.add_resource(SavePatientResource, '/savePatient')
    api.add_resource(GetExcelFileListResource, '/getExcelFileList')
    api.add_resource(GetPatientInfoListResource, '/getPatientInfoList')
    api.add_resource(GetPatientInfoResource, '/getPatientInfo')
    api.add_resource(GetImageFeatureResource, '/getImageFeature')

    # 公用接口
    api.add_resource(LoginResource, '/login')
    api.add_resource(GetFileResource, '/getFile')
    api.add_resource(GetFileListResource, '/getFileList')

    app.register_blueprint(bp)
